<?php
/**
 * article table
 * 'title', 'short_title', 'descrition', 'image_id', 'image_id_list', 'content', 'uid'
 *
 */
namespace backend\models;

use Yii;
use yii\db\ActiveRecord;
class Article extends ActiveRecord{
    public $title;
    public $status;

	public function scenarios(){
		return [
			'create' => ['title', 'short_title', 'description', 'image_id', 'image_id_list', 'content', 'uid', 'cid'],

			'update' => ['title', 'short_title', 'description', 'image_id', 'image_id_list', 'content'],

            'select'=>['title','status'],
        ];
	}

	public function rules(){

		return [
		    ['title','string','on'=>'select'],
            ['status','integer','on'=>'select'],
			[['title', 'short_title', 'description'], 'required'],
			[['title', 'short_title'], 'string', 'max' => 50, 'min' => 1,],
			['description', 'string', 'max' => 500, 'min' => 0,],
			[['image_id', 'image_id_list'], 'exist', 'targetClass' => 'backend\models\Files', 'targetAttribute' => ['image_id'=> 'id']],
			['content', 'default', 'value' => function(){
				return $this->content;
			}],
			['cid', 'exist', 'targetClass' => 'backend\models\Category', 'targetAttribute' => ['cid'=> 'id']],
        ];
	}

    public function attributeLabels(){
        return [
            'title' => '文章标题',
            'short_title' => '小标题',
            'description' => '简介',
            'image_id' => '文章封面',
            'image_id_list' => '文章图集',
            'content' => '正文内容',
            'cid' => '文章分类',
        ];
    }
}